home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wics.zip / IDLG.CPP < prev    next >
C/C++ Source or Header  |  1993-03-03  |  4KB  |  150 lines

  1. //==============================================================================================
  2. //
  3. //    Windows Interface Construction Set
  4. //    Version 1.00
  5. //
  6. //    IDLG.CPP - Indirect Dialog Class Source File
  7. //    Copyright ⌐ 1993 by Microdyne Development Technologies.
  8. //    All rights reserved.
  9. //==============================================================================================
  10.  
  11. #include <idlg.h>
  12.  
  13. extern PTWindowsObject DlgCreationWindow;
  14.  
  15. /*------------------------------------------------------------------------------------------*/
  16. /*    Class TIndirectDialog                                                                    */
  17. /*------------------------------------------------------------------------------------------*/
  18. /*                                                                                          */
  19. /*    Abstract:                                                                               */
  20. /*                                                                                          */
  21. /*    The TIndirectDialog class defines an indirect dialog object. The dialog template is     */
  22. /*    built in memory utilizing the TDialogTemplate object and then passed to this class        */
  23. /*    creates the dialog based upon this template.                                            */
  24. /*                                                                                          */
  25. /*------------------------------------------------------------------------------------------*/
  26.  
  27. static BOOL RegFails(void *AWindowsObject, void *)
  28. {
  29.   return !((PTWindowsObject)AWindowsObject)->Register();
  30. }
  31.  
  32. TIndirectDialog::TIndirectDialog(PTWindowsObject AParent, PTDialogTemplate pdt)
  33.                 : TDialog(AParent, 0)
  34. {
  35.     ADialogTemplate = pdt;
  36. }
  37.  
  38. TIndirectDialog::~TIndirectDialog()
  39. {
  40.     if ( !IsModal )
  41.         GlobalUnlock (ADialogTemplate->GetHandle());
  42.  
  43.     delete ADialogTemplate;
  44. }
  45.  
  46. /*    Creates an MS-Windows modeless dialog, and associates the modeless dialog interface
  47.     element with the TIndirectDialog.  Creation and association are not attempted if the Status
  48.     data member is non-zero.
  49. */
  50.  
  51. BOOL TIndirectDialog::Create()
  52. {
  53.     HWND                HParent;
  54.  
  55.     IsModal = FALSE;            // GetClassName called from Register needs to know this.
  56.  
  57.     if ( Status == 0 && Register() )
  58.     {
  59.         DisableAutoCreate();
  60.         EnableKBHandler();
  61.  
  62.         if ( !Parent )
  63.             HParent = 0;
  64.         else
  65.             HParent = Parent->HWindow;
  66.  
  67.         DlgCreationWindow = this;
  68.  
  69.         /*    Register all the dialog's child objects (for custom control support) */
  70.  
  71.         if ( FirstThat(RegFails, NULL) == NULL )
  72.         {
  73.             lpDialog = (LPDIALOGBOXHEADER) GlobalLock (ADialogTemplate->GetHandle()) ;
  74.  
  75.             HWindow = CreateDialogIndirectParam(GetModule()->hInstance, lpDialog, HParent, (DLGPROC)GetInstance(), Attr.Param);
  76.  
  77.             if ( !HWindow )
  78.                 Status = EM_INVALIDWINDOW;
  79.         }
  80.         else
  81.             Status = EM_INVALIDCHILD;
  82.  
  83.         DlgCreationWindow = NULL;
  84.     }
  85.  
  86.     return (Status == 0);
  87. }
  88.  
  89. /*    Creates an MS-Windows modal dialog.  Associates the modal dialog interface element with
  90.     the TIndirectDialog.  Creation and association is not attempted if the Status data member is
  91.     non-zero.
  92. */
  93.  
  94. int TIndirectDialog::Execute()
  95. {
  96.     HWND             HParent;
  97.     int             ReturnValue = -1;
  98.     PTWindowsObject OldKBHandler;
  99.  
  100.     IsModal = TRUE;
  101.  
  102.     if ( Status == 0  && Register() )
  103.     {
  104.         DisableAutoCreate();
  105.  
  106.         /*    Enable the keyboard handler. Although modal dialogs do their own keyboard
  107.             handling, we use the WB_KBHANDLER flag for WM_COMMAND processing.
  108.         */
  109.  
  110.         EnableKBHandler();
  111.  
  112.         if ( GetApplication() )
  113.             OldKBHandler = GetApplication()->KBHandlerWnd;
  114.  
  115.         if ( !Parent )
  116.             HParent = 0;
  117.         else
  118.             HParent = Parent->HWindow;
  119.  
  120.         DlgCreationWindow = this;
  121.  
  122.         /*    Register all the dialog's child objects (for custom control support) */
  123.  
  124.         if ( FirstThat(RegFails, NULL) == NULL )
  125.         {
  126.             ReturnValue = DialogBoxIndirectParam(GetModule()->hInstance, ADialogTemplate->GetHandle(), HParent, (DLGPROC)GetInstance(), Attr.Param);
  127.  
  128.             // -1 if the function cannot create the dialog box
  129.  
  130.             if ( ReturnValue == -1)
  131.                 Status = EM_INVALIDWINDOW;
  132.         }
  133.         else
  134.             Status = EM_INVALIDCHILD;
  135.  
  136.         DlgCreationWindow = NULL;
  137.  
  138.         if ( GetApplication() )
  139.             GetApplication()->SetKBHandler(OldKBHandler);
  140.     }
  141.  
  142.     if ( Status == 0 )
  143.         delete this;
  144.     else
  145.         if (ReturnValue != -1)
  146.             ReturnValue = BAD_DIALOG_STATUS;            // dialog ran, but status != 0
  147.  
  148.     return ReturnValue;
  149. }
  150.